package com.acme.bankapp.domain.bank;

import java.io.Serializable;

public class Client implements Serializable {
	private String name;
	private Gender gender;
	private Account account;
	private int clientid;
	private static int idClient=0;
	public Client(String name, Gender gender, Account account) {
		this.name = name;
		this.gender = gender;
		this.account = account;
		idClient++;
		this.clientid=this.clientid+idClient;
	}
	
	public String getName() {
		return name;
	}
	
	public String getClientSalutation(){
		return gender.getSalutation()+getName();
	}

	public Account getAccount() {
		return account;
	}

	public int getClientid() {
		return clientid;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + clientid;
		result = prime * result + ((gender == null) ? 0 : gender.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Client)) {
			return false;
		}
		Client other = (Client) obj;
		if (account == null) {
			if (other.account != null) {
				return false;
			}
		} else if (!account.equals(other.account)) {
			return false;
		}
		if (clientid != other.clientid) {
			return false;
		}
		if (gender != other.gender) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Client [ "+gender.getSalutation()+getName() + ", accountBalance="
				+ account.getBalance() + ", clientid=" + clientid + "]";
	}
	
}
